package com.yonyou.sto;

import com.yonyou.sto.modules.ims.dto.CallbackInvoiceParam;
import com.yonyou.sto.modules.ims.service.CacheService;
import com.yonyou.sto.modules.ims.service.OpenBillService;
import com.yonyou.sto.modules.ums.service.ConfigNameServic;
import net.jodah.expiringmap.ExpirationListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@EnableTransactionManagement
public class StoInvoiceApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(StoInvoiceApplication.class, args);
    }
    @Autowired
    private CacheService cacheService;
    @Autowired
    OpenBillService openBillService;
    @Override
    public void run(String... args) throws Exception {
        configNameServic.setInitCofigName();
        ExpirationListener<String, CallbackInvoiceParam> expirationListener = ((theKey, theValue)->{
            openBillService.as();
            openBillService.callbackInvoiceApply(theValue);
        });
        cacheService.getCahe().addExpirationListener(expirationListener);
    }
    @Autowired
    private ConfigNameServic configNameServic;

}
